package com.dev.stream;

import com.dev.stream.pojo.Person;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Stream;

/**
 * @author 戴 骥
 * @date 2021-09-05 16:12
 */
public class CreatStream {
    @Test
    public void creatStream() {
        //1. Collection.stream（）方法用集合创建
        List<String> list = Arrays.asList("1", "2", "3");
        Stream<String> stream = list.stream();
        //2. Arrays.stream(T[] array) 方法用数组创建
        Stream<String> stream1 = list.stream();
        //3.  使用Stream的静态方法：of()、iterate()、generate()
        Stream<Object> objectStream = Stream.of(1, 2, 3, "2", new Person());
        Stream<Integer> iterate = Stream.iterate(99, a -> a + 1).limit(2);
        //iterate.forEach(System.out::println);
        AtomicInteger integer = new AtomicInteger(10);
        Stream<Integer> limit1 = Stream.generate(() -> integer.incrementAndGet()).limit(2);
        limit1.forEach(System.out::println);

    }


}
